
import { Component } from "react";

class Counter extends Component {
    constructor(){
        super();
        this.state = {
            count: 123
        }
        // 为 handler 函数绑定 this 后重新赋值给 this.handler 属性
        this.handler = this.handler.bind( this );
    }
    render(){
        console.log( 'render => ' , this );
        return ( <button onClick={ this.handler }>{ this.state.count }</button> )
    }
    handler(){
        // 方法 setState 是从 Component 继承的，用来修改组件的状态
        this.setState({
            count: this.state.count + 1
        });
    }
    componentDidMount(){
        console.log( 'mount: ' , this );
    }
}

// console.log( Object.getOwnPropertyNames( Counter.prototype ) );
// console.log( Object.getOwnPropertyNames( Component.prototype ) );

export default Counter ;